<?php

namespace app\health\job;

use app\health\library\notice\DingTalk;
use app\health\model\HealthOrder;
use app\health\service\SystemNoticeService;
use think\queue\Job;

class SystemNoticeJob extends BaseJob
{

    /**
     * 延迟发送消息队列
     * @param Job $job
     * @param $data
     * @return void
     */
    public function delayMessage(Job $job, $data): void
    {
        // 删除 job
        $job->delete();
        $dingTalk = !empty($data['ding_talk']) ? unserialize($data['ding_talk']) : '';
        if ($dingTalk instanceof DingTalk) {
            $dingTalk->send();
        }
    }

    /**
     * 新订单提醒
     * @param Job $job
     * @param $data
     * @return void
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function newGoodsOrderMessage(Job $job, $data): void
    {
        // 删除 job
        $job->delete();
        $order = HealthOrder::where('id', $data['order_id'])->find();
        if ($order) {
            SystemNoticeService::develop('新商品订单提醒', "### 新商品订单提醒\n\n>订单号:{$order['order_no']}\n\n>用户手机:{$order['mobile']}\n\n>订单金额:{$order['pay_price']}\n\n请尽早处理", true);
        }
    }

    public function fuluEquityMessage(Job $job, $data): void
    {
        $job->delete();
        SystemNoticeService::develop('会员专属权益领取通知', "### 今日已领取会员周卡权益次数<font color=\"#FF0000\">{$data['num']}</font>\n\n>用户手机:<font color=\"#FF0000\">{$data['mobile']}</font>\n\n>福禄权益:<font color=\"#FF0000\">{$data['goods_name']}</font>\n\n请尽早处理", true);
    }
}
